//
//  WKBleManager.h
//  ourToken
//
//  Created by wakeup on 2018/6/14.
//  Copyright © 2018年 ourtoken. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import "WKBaseHeader.h"

#pragma mark - 通知
//蓝牙状态为：开
#define kTag_Phone_Ble_On               @"kTag_Phone_Ble_On"

//蓝牙状态为：关
#define kTag_Phone_Ble_Off              @"kTag_Phone_Ble_Off"

//发现设备
#define kTag_Phone_Discover_Device      @"kTag_Phone_Discover_Device"

//连上设备
#define kTag_Device_Connected           @"kTag_Device_Connected"

//断开设备
#define kTag_Device_Disconnected        @"kTag_Device_Disconnected"

#define bleSelf [WKBleManager sharedBleManager]

@protocol BleDelegete <NSObject>

@optional
//芯片升级返回的数据(升级设备使用)
-(void)bleNotifyResponseData:(NSMutableData*)data type:(int)type;

@end

@interface WKBleManager : NSObject

@property (weak, nonatomic) id<BleDelegete> delegete;

//蓝牙管理者
@property (nonatomic, strong) CBCentralManager *centralManager;

//处于连接状态的设备
@property (nonatomic, strong) CBPeripheral *activePeripheral;

//搜索到的所有设备(包括重复的,用来作为过滤条件)
@property (nonatomic, strong) NSMutableArray *peripheralArray;

//搜索到的不重复的设备
@property (nonatomic, strong) NSMutableArray *bleArray;

//手机是否打开蓝牙
@property (nonatomic, assign) BOOL on;


+ (WKBleManager *)sharedBleManager;


//开始搜索设备,默认5秒后停止搜索(重复扫描需要清空：peripheralArray、bleArray)
- (void)startFindBleDevices;

//停止搜索设备
- (void)stopFindBleDevices;

//连接设备
- (void)connectBleDevice:(CBPeripheral *)peripheral;

//断开设备
- (void)disconnectBleDevice:(CBPeripheral *)peripheral;

#pragma mark - 通讯指令
//查找手环
- (void)sendSeatchBracelet;

//获取设备初始化状态
- (void)sendGetDeviceInitStatus;

//设置钱包密码
- (void)sendSetDevicePassword:(NSString *)password;

//获取钱包密码
- (void)sendGetDevicePassword;

//保存钱包秘钥
- (void)sendSavePurseKey:(NSString *)key;

//获取钱包秘钥
- (void)sendGetPurseKey;

#pragma mark - 固件升级指令
//进去ISP模式(升级设备使用)
- (void)sendEnterISP;

//发送升级数据(升级设备使用)
- (int)sendFileData:(NSMutableData*)data len:(int)len;

//设备复位(升级设备使用)
- (void)sendCmdData:(NSMutableData *)data;

@end
